<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <script>
   
     var  arr = [a,b,b,b]
     function findall(arr,x)
     {
         var l = arr.length;
         var re = [];
         k=0;
         p=0;
          for(var i=0;i<l;i++)
          {
             k= arr.indexOf(x,p);
             if(k!=-1)
             {
                re.push(k) 
             } 
             p++;
          }
          return re;
     } 
     document.write(findall(arr,"d"))
     function count(arr,x)
     {
       var num = 0;
       for(var i =0;i<arr.length;i++)
       {
           if(arr[i]==x)
           {
               num++;
           }
       }
      

     }
    document.write(count(arr,"b"))
    </script>
</body>
</html>